//
//  AssistanceUnitTableViewCell.m
//  WideHelp
//
//  Created by ENERGY on 2018/8/21.
//  Copyright © 2018年 ENERGY. All rights reserved.
//

#import "AssistanceUnitTableViewCell.h"

@interface AssistanceUnitTableViewCell()
@property (nonatomic, strong)UIView * topWhiteView;
@property (nonatomic, strong)UIView * borderView;
@property (nonatomic, strong)UILabel * titleNameLab;
@property (nonatomic, strong)UIView * bottomWhiteView;
@property (nonatomic, strong)UIImageView * iconImg;
@property (nonatomic, strong)UILabel * contentLab;
@property (nonatomic, strong)UIButton * arrowBtn;
@property (nonatomic, strong)NSString * unitID;
@property (nonatomic, strong)NSString * status;
@property (nonatomic, strong)NSString * urlStr;
@property (nonatomic, strong)UIButton * coverBtn;
@end
@implementation AssistanceUnitTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = getColor(@"f5f5f5");
        __weak typeof (self)weakSelf = self;
        [self.contentView addSubview:self.topWhiteView];
        [self.contentView addSubview:self.borderView];
        [self.contentView addSubview:self.titleNameLab];
        [self.contentView addSubview:self.bottomWhiteView];
        [self.contentView addSubview:self.iconImg];
        [self.contentView addSubview:self.contentLab];
        [self.contentView addSubview:self.arrowBtn];
        [self.contentView addSubview:self.coverBtn];
        [self.topWhiteView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.equalTo(weakSelf.contentView);
            make.height.mas_offset(42/WIDTH_6_SCALE);
        }];
        [self.borderView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(weakSelf.contentView);
            make.top.equalTo(weakSelf.topWhiteView.mas_bottom);
            make.height.mas_offset(1/WIDTH_6_SCALE);
        }];
        [self.titleNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.topWhiteView.mas_left).mas_offset(15/WIDTH_6_SCALE);
            make.height.equalTo(weakSelf.topWhiteView.mas_height);
            make.right.equalTo(weakSelf.topWhiteView.mas_right).mas_offset(-15/WIDTH_6_SCALE);
        }];
        [self.bottomWhiteView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(weakSelf.contentView);
            make.top.equalTo(weakSelf.borderView.mas_bottom);
            make.height.mas_offset(101/WIDTH_6_SCALE);
        }];
        [self.iconImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.contentView.mas_left).mas_offset(15/WIDTH_6_SCALE);
            make.top.equalTo(weakSelf.borderView.mas_bottom).mas_offset(16/WIDTH_6_SCALE);
            make.width.height.mas_offset(70/WIDTH_6_SCALE);
        }];
        [self.contentLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.iconImg.mas_right).mas_offset(10/WIDTH_6_SCALE);
            make.top.equalTo(weakSelf.iconImg.mas_top);
            make.bottom.lessThanOrEqualTo(weakSelf.iconImg.mas_bottom);
            make.right.equalTo(weakSelf.arrowBtn.mas_left).mas_offset(18/WIDTH_6_SCALE);
        }];
        [self.arrowBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(weakSelf.contentView.mas_right).mas_offset(-15/WIDTH_6_SCALE);
            make.centerY.equalTo(weakSelf.iconImg.mas_centerY);
            make.width.mas_offset(7/WIDTH_6_SCALE);
            make.height.mas_offset(10/WIDTH_6_SCALE);
        }];
        [self.coverBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.contentLab.mas_right);
            make.right.equalTo(weakSelf.contentView);
            make.top.equalTo(weakSelf.borderView);
            make.bottom.equalTo(weakSelf.bottomWhiteView);
        }];
    }return self;
}
- (UIView *)topWhiteView{
    if (!_topWhiteView) {
        _topWhiteView = [[UIView alloc] init];
        _topWhiteView.backgroundColor = [UIColor whiteColor];
    }return _topWhiteView;
}
- (UIView *)borderView{
    if (!_borderView) {
        _borderView = [[UIView alloc] init];
        _borderView.backgroundColor = getColor(@"eeeeee");
    }return _borderView;
}
- (UILabel *)titleNameLab{
    if (!_titleNameLab) {
        _titleNameLab = [[UILabel alloc] init];
        _titleNameLab.font = DEF_FontSize_14;
        _titleNameLab.textColor = [UIColor blackColor];
        _titleNameLab.textAlignment = NSTextAlignmentLeft;
        _titleNameLab.text = @"医院名";
    }return _titleNameLab;
}
- (UIView *)bottomWhiteView{
    if (!_bottomWhiteView) {
        _bottomWhiteView = [[UIView alloc] init];
        _bottomWhiteView.backgroundColor = [UIColor whiteColor];
    }return _bottomWhiteView;
}
- (UIImageView *)iconImg{
    if (!_iconImg) {
        _iconImg = [[UIImageView alloc] init];
        
    }return _iconImg;
}
- (UILabel *)contentLab{
    if (!_contentLab) {
        _contentLab = [[UILabel alloc] init];
        _contentLab.font = DEF_FontSize_13;
        _contentLab.textColor = getColor(@"9b9b9b");
        _contentLab.textAlignment = NSTextAlignmentLeft;
        _contentLab.lineBreakMode = 0;
        _contentLab.numberOfLines = 0;
        _contentLab.text = @"aaaaaaa";
    }return _contentLab;
}
- (UIButton *)arrowBtn{
    if (!_arrowBtn) {
        _arrowBtn = [[UIButton alloc] init];
        [_arrowBtn setBackgroundImage:[UIImage imageNamed:@"next_icon"] forState:UIControlStateNormal];
    }return _arrowBtn;
}
- (UIButton *)coverBtn{
    if (!_coverBtn) {
        _coverBtn = [[UIButton alloc] init];
        [_coverBtn addTarget:self action:@selector(arrowBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [_coverBtn setBackgroundColor:[UIColor clearColor]];
    }return _coverBtn;
}
- (void)setModel:(NSDictionary *)model{
    _model = model;
    self.titleNameLab.text = model[@"unit_name"];
    self.contentLab.text = model[@"unit_desc"];
    self.unitID = model[@"unit_id"];
    if ([model[@"unit_img"] isEqualToString:@""]) {
        self.iconImg.image = [UIImage imageNamed:@"maself_bg"];
    }else{
        [self.iconImg sd_setImageWithURL:[NSURL URLWithString:model[@"unit_img"]]];
    }
    self.status = model[@"status"];
    self.urlStr = model[@"link"];
}
#pragma mark - action
- (void)arrowBtnClick:(UIButton *)sender{
    NSLog(@"跳页");
    if (self.arrowBtnBlock) {
        self.arrowBtnBlock(self.urlStr, self.titleNameLab.text);
    }
}
@end
